package Practice;

import java.util.Scanner;

public class TextProcessor {
    static Scanner read = new Scanner(System.in);    //设定读取
    static int d = read.nextInt();    //定义d，读取
    static String str = read.next();    //定义字符串，读取

    public static void main(String[] args) {
        //主方法
        for (int x0 = 0; x0 < d; x0++) {    //循环d次
            switch (read.nextInt()) {    //switch，可以用if代替
                case 1: {    //读取下一个字符串，进入方法一
                    one(read.next());
                    break;
                }
                case 2: {
                    two(read.nextInt(), read.nextInt());
                    break;
                }
                case 3: {
                    three(read.nextInt(), read.next());
                    break;
                }
                case 4: {
                    four(read.next());
                    break;
                }
            }
        }
    }

    static void one(String s) {    //方法一
        str = str + s;    //直接连接字符串
        System.out.println(str);    //输出
    }

    static void two(int a, int b) {    //方法二
        str = str.substring(a, a + b);    //取第a个开始，读取b个
        System.out.println(str);
    }

    static void three(int line, String s) {    //方法三
        String s1 = str.substring(0, line);    //将分界点两端分开读取
        String s2 = str.substring(line, str.length());
        str = s1 + s + s2;    //暴力连接
        System.out.println(str);
    }

    static void four(String s) {    //方法四
        System.out.println(str.indexOf(s));    //indexOf() 方法返回值在字符串中第一次出现的位置
    }
}